package com.heima.article.controller;

import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.article.dto.ArticleInfoDto;
import com.heima.article.service.IApArticleService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章信息表，存储已发布的文章接口")
public class ApArticleController {

    @Autowired
    private IApArticleService apArticleService;

    /**
     * 保存和更新文章
     * @param dto
     * @return
     */
    @PostMapping
    public ResponseResult<Long> saveArticle(@RequestBody ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    /**
     * 加载文章
     * @param dto
     * @return
     */
    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,1);
    }

    /**
     * 加载更多(下一页)
     * @param dto
     * @return
     */
    @PostMapping("loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,0);
    }

    /**
     * 加载最新
     * @param dto
     * @return
     */
    @PostMapping("loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,1);
    }

    @PostMapping("load_article_info")
    public ResponseResult loadInfo(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadInfo(dto);
    }
}
